/*
 * @Author       : Xu Xiaokang
 * @Email        :
 * @Date         : 2025-05-07 23:17:14
 * @LastEditors  : Xu Xiaokang
 * @LastEditTime : 2025-05-07 23:19:42
 * @Filename     :
 * @Description  :
*/

/*
! 模块功能: 可综合的伪随机数生成器
* 思路:
* 1.
~ 注意:
~ 1.
% 其它
*/

`default_nettype none

module lfsr (
  output reg  [15:0] random_num,
  input  wire [15:0] seed,
  input wire clk,
  input wire rstn      // 复位时设置种子
);

// LFSR反馈多项式：x^16 + x^14 + x^13 + x^11 + 1
wire feedback = random_num[15] ^ random_num[13] ^ random_num[12] ^ random_num[10];

always @(posedge clk) begin
  if (~rstn)
    if (seed == 0)
      random_num <= 16'hACE1;  // 初始化种子（非零值）
    else
      random_num <= seed;
  else
    random_num <= {random_num[14:0], feedback};
end

endmodule
`resetall